
#include <stdio.h>
#include <stdlib.h>

/* Three ways to return array out of function
 * static
 * buff
 * malloc
 * */

int* two_sum(int* nums, int num_size, int target){
	int i, j;
	static int result[2];
	for(i = 0; i < num_size; i++){
		for(j = i+1; j < num_size; j++){
			if (nums[i] + nums[j] == target){
				result[0] = i;
				result[1] = j;
				printf("%d\n", i);
				printf("%d\n", j);
				return result;
			}
		}
	}
}

void two_sum_1(int *nums, int num_size, int target, int *buf){
	int i,j;
	for(i=0; i<num_size; i++){
		for(j=i+1; j<num_size; j++){
			if(nums[i]+nums[j] == target){
				buf[0] = i;
				buf[1] = j;
			}
		}	
	}
}

int *two_sum_2(int *nums, int num_size, int target){
	int i,j;
	int *result = malloc(2);
	if(result == NULL)
		return NULL;
	for(i=0; i<num_size; i++){
		for(j=i+1; j<num_size; j++){
			if(nums[i]+nums[j] == target){
				result[0] = i;
				result[1] = j;
				return result;
			}
		}	
	}

}
int main(){
	int nums[] = {3, 2, 4};
	int target = 6;
	int result[2];
	//result = two_sum(nums, 4, target);
	//result = two_sum_2(nums, 4, target);
	two_sum_1(nums, 3, target, result);
	int i;
	//printf("%d\n", *result);
	for(i = 0; i < 2; i++){
		printf("%d\n", result[i]);
	}
}
